package org.come.mouslisten;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTextField;
import javax.swing.text.BadLocationException;

import org.come.Frame.LingbaoJframe;
import org.come.Frame.ZhuFrame;
import org.come.model.Lingbao;

import com.tool.Document.RichDocument;
import com.tool.role.RoleLingFa;
import com.tool.role.RoleProperty;

/**
 * 灵宝法宝翻页监听
 * 
 * @author Administrator
 */
public class LingFaFanYeMouslisten implements MouseListener {
    // true 装备页的 false属性页的
    public static boolean shijian = true;
    // true表示灵宝 flase表示法宝
    private boolean type;
    // 表示格子位置 -1表示灵宝装备 或者法宝1装备 2表示法宝2装备
    private int path;

    public LingFaFanYeMouslisten(boolean type, int path) {
        super();
        this.type = type;
        this.path = path;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub
        Lingbao lingbao = getLingbao();
        if (lingbao != null) {
            if (e.getButton() == MouseEvent.BUTTON3) {// 右键点击
                if (shijian) {
                    if (path >= 0) {
                        RoleLingFa.getRoleLingFa().choseuse(lingbao, true);
                    } else {
                        RoleLingFa.getRoleLingFa().choseuse(lingbao, false);
                    }
                    // 刷新抗性
                    RoleProperty.ResetEw();
                } else {
                    RoleLingFa.getRoleLingFa().choseBao = lingbao;
                    LingbaoJframe.getLingbaoJframe().getLingbaoJpanel().getLingbaoCardJpanel().getAttributeJpanel()
                            .shuxingzhanshi(lingbao);
                }
            } else if (e.isShiftDown() && e.getButton() == MouseEvent.BUTTON1) {
                try {
                    JTextField SendMes = ZhuFrame.getZhuJpanel().getSendMes();
                    ((RichDocument) SendMes.getDocument()).insertRich(SendMes.getCaretPosition(), 4,
                            lingbao.getBaoid(), "[" + lingbao.getBaoname() + "]", "G", null);
                } catch (BadLocationException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        Lingbao lingbao = getLingbao();
        if (lingbao != null) {
            ZhuFrame.getZhuJpanel().creatlingtext(lingbao);
        }
    }

    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub
        ZhuFrame.getZhuJpanel().clearlingtext();
    }

    // 获取lingbao
    public Lingbao getLingbao() {
        Lingbao lingbao = null;
        if (path < 0) {
            if (type) {
                lingbao = RoleLingFa.getRoleLingFa().equipBao[0];
            } else if (path == -1) {
                lingbao = RoleLingFa.getRoleLingFa().equipBao[1];
            } else {
                lingbao = RoleLingFa.getRoleLingFa().equipBao[2];
            }
        } else {
            if (type) {
                lingbao = RoleLingFa.getRoleLingFa().getlingbao(path);
            } else {
                lingbao = RoleLingFa.getRoleLingFa().getfabao(path);
            }
        }
        return lingbao;
    }
}
